package com.zfsoft.zfoa.onduty.wage.dao;
import java.sql.SQLException;
import com.zfsoft.zfoa.dao.BasicDAO;
import com.zfsoft.zfoa.onduty.wage.entitys.Wagefather;
public class WagefatherDAO extends BasicDAO {
	public Wagefather getInstance(String bh)  {
		Wagefather wagefather = new Wagefather();
		try {String sql="select * from wagefather where id=?";
		conn=this.getConn();
		ps = conn.prepareStatement(sql);
		ps.setString(1, bh);
		rs = ps.executeQuery();
		if (rs.next()) {
		wagefather.setId(rs.getString("id"));
		wagefather.setName(rs.getString("name"));
		wagefather.setDepno(rs.getString("depno"));
		wagefather.setDepname(rs.getString("depname"));
		wagefather.setMon(rs.getString("mon"));
		wagefather.setTime(rs.getString("time"));
		wagefather.setAssessor(rs.getString("assessor"));
		wagefather.setAssessorname(rs.getString("assessorname"));
		wagefather.setCreator(rs.getString("creator"));
		wagefather.setCreatorname(rs.getString("creatorname"));
		}
		closeStmt();
		} catch (SQLException e) {
		e.printStackTrace();
		} finally {
		closeConn();
		}
		return wagefather;
		}
		public Boolean update(String bh, Wagefather wagefather) {
		Boolean res = true;
		String sql ="";
		try {
		sql="UPDATE wagefather SET id=?,name=?,depno=?,depname=?,mon=?,time=?,assessor=?,assessorname=?,creator=?,creatorname=? WHERE id=?";
		conn = this.getConn();
		conn.setAutoCommit(false);
		ps = conn.prepareStatement(sql);
		ps.setString(1,wagefather.getId());
		ps.setString(2,wagefather.getName());
		ps.setString(3,wagefather.getDepno());
		ps.setString(4,wagefather.getDepname());
		ps.setString(5,wagefather.getMon());
		ps.setString(6,wagefather.getTime());
		ps.setString(7,wagefather.getAssessor());
		ps.setString(8,wagefather.getAssessorname());
		ps.setString(9,wagefather.getCreator());
		ps.setString(10,wagefather.getCreatorname());
		ps.setString(11,bh);
		ps.executeUpdate();
		closeStmt();
		} catch (SQLException e) {
		System.out.println(sql);
		e.printStackTrace();
		try {
		conn.rollback();
		} catch (SQLException e1) {
		System.out.println(sql);
		e1.printStackTrace();
		}
		res = false;
		} finally {
		try {conn.commit();} catch (SQLException e) {
		System.out.println(sql);e.printStackTrace();}closeConn();}return res;}public Boolean insert(Wagefather wagefather)  {
		Boolean res = true;String sql ="";try {sql = "insert into wagefather(id,name,depno,depname,mon,time,assessor,assessorname,creator,creatorname) values(?,?,?,?,?,?,?,?,?,?)";conn = this.getConn();
		conn.setAutoCommit(false);
		ps = conn.prepareStatement(sql);
		ps.setString(1, wagefather.getId());
		ps.setString(2, wagefather.getName());
		ps.setString(3, wagefather.getDepno());
		ps.setString(4, wagefather.getDepname());
		ps.setString(5, wagefather.getMon());
		ps.setString(6, wagefather.getTime());
		ps.setString(7, wagefather.getAssessor());
		ps.setString(8, wagefather.getAssessorname());
		ps.setString(9, wagefather.getCreator());
		ps.setString(10, wagefather.getCreatorname());
		ps.executeUpdate();
		closeStmt();
		} catch (SQLException e) {
		System.out.println(sql);
		e.printStackTrace();
		try {
			conn.rollback();
		} catch (SQLException e1) {
			System.out.println(sql);
			e1.printStackTrace();
		}
		res = false;
		} finally {
		try {
			conn.commit();
		} catch (SQLException e) {
			System.out.println(sql);
			e.printStackTrace();
		}
		closeConn();
		}
		return res;
		}
		
	
}